package com.cn.crmsystem.service.businessService.Impl;

import com.cn.crmsystem.mapper.businessMapper.InvoiceMapper;
import com.cn.crmsystem.pojo.Invoice;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.Order;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.InvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class InvoiceServiceImpl implements InvoiceService{
    @Autowired
    private InvoiceMapper invoiceMapper;
    @Override
    public ResultJson selectinvoiceAll(Map map) {

        List selectinvoiceAll = invoiceMapper.selectinvoiceAll(map);
        ResultJson resultJson = new ResultJson();
        if (selectinvoiceAll != null) {
            resultJson.getSuccess("成功",selectinvoiceAll);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson addInvoice(Invoice invoice, Login login) {
        HashMap<Object,Object> map = new HashMap<>();
        map.put("invoice",invoice);
        map.put("login",login);
        int addInvoice = invoiceMapper.addInvoice(map);
        ResultJson resultJson = new ResultJson();
        if (addInvoice>0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson updateInvoice(Integer id) {

        int updateInvoice = invoiceMapper.updateInvoice(id);
        ResultJson resultJson = new ResultJson();
        if (updateInvoice >0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return  resultJson;
    }

    @Override
    public ResultJson deleteByIdInvoice(Integer id) {
        int deleteByIdInvoice = invoiceMapper.deleteByIdInvoice(id);
        ResultJson resultJson = new ResultJson();
        if (deleteByIdInvoice>0){
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }
}
